package com.xu.modules.controller;

import com.xu.common.domain.MyResult;
import com.xu.modules.service.CommentService;
import com.xu.modules.service.bo.CommentBo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author xu
 * @since 2022-07-26
 */
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {
    private final CommentService commentService;

    @PostMapping("/add")
    public MyResult add(@RequestBody @Valid CommentBo commentBo){
        commentService.add(commentBo);
        return MyResult.ok();
    }

    @GetMapping("/tree")
    public MyResult tree(@RequestParam Long articleId){
        return MyResult.ok(commentService.listByArticle(articleId));
    }
}
